#include <stdio.h>
#include <string.h>
int main()
{
    char b[1000];
    while (scanf("%s",b)!=EOF)
    {
        int a=0;
        for (int i=0;i<strlen(b);i++)a+=b[i]-'0';
        if (a==0)break;
        while (a>=10)
        {
            int t=0;
            while (a!=0)
            {
                t+=a%10;
                a/=10;
            }
            a=t;
        }
        printf("%d\n",a);
    }
    return 0;
}
